import request from '@/utils/request'
import type {
  CommonResult,
  PageResult,
  UserVO,
  UserLoginRequest,
  UserAddRequest,
  UserUpdateRequest,
  UserQueryRequest,
  BaseRequest,
} from '@/types/api'

/**
 * 用户登录
 */
export function login(data: UserLoginRequest): Promise<CommonResult<UserVO>> {
  return request({
    url: '/user/login',
    method: 'post',
    data,
  })
}

/**
 * 用户登出
 */
export function logout(): Promise<CommonResult<boolean>> {
  return request({
    url: '/user/logout',
    method: 'post',
  })
}

/**
 * 获取当前用户信息
 */
export function getCurrentUser(): Promise<CommonResult<UserVO>> {
  return request({
    url: '/user/getCurrentUser',
    method: 'get',
  })
}

/**
 * 新增用户
 */
export function addUser(data: UserAddRequest): Promise<CommonResult<number>> {
  return request({
    url: '/user/add',
    method: 'post',
    data,
  })
}

/**
 * 删除用户
 */
export function deleteUser(data: BaseRequest): Promise<CommonResult<boolean>> {
  return request({
    url: '/user/delete',
    method: 'post',
    data,
  })
}

/**
 * 更新用户
 */
export function updateUser(data: UserUpdateRequest): Promise<CommonResult<boolean>> {
  return request({
    url: '/user/update',
    method: 'post',
    data,
  })
}

/**
 * 分页查询用户
 */
export function pageUser(params: UserQueryRequest): Promise<CommonResult<PageResult<UserVO>>> {
  return request({
    url: '/user/page',
    method: 'get',
    params,
  })
}

/**
 * 获取用户详情
 */
export function getUserById(id: string): Promise<CommonResult<UserVO>> {
  return request({
    url: '/user/get',
    method: 'get',
    params: { id },
  })
}

